﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using db;
using System.Collections;

namespace DMSMT.MaterialMgr
{
    public partial class MaterialInfo : Form
    {
        public MaterialInfo()
        {
            InitializeComponent();
        }

        private void MaterialInfo_Load(object sender, EventArgs e)
        {

        }

        private void btExport_Click(object sender, EventArgs e)
        {
            string sql = "select org_id,org_name from t_sys_organization where AGENTS_CODE is not null";
            List<Hashtable> lOrgs = Dao.search("dc", sql);
            foreach (Hashtable org in lOrgs)
            {
                ExportMInfo(org);
            }
        }

        //导出物料
        private void ExportMInfo(Hashtable org)
        {
            throw new NotImplementedException();
        }

        private void btSearch_Click(object sender, EventArgs e)
        {
            string mcode = tbMC.Text.Trim();
            string netcode = tbNetCode.Text.Trim();
            if (string.IsNullOrEmpty(mcode))
            {
                Log.LogError("图号不能为空!");
                return;
            }

            //所有一体化物料
            string sqlAll = "SELECT T.PJSX,\n" +
    "       S.\"AlterDay\",\n" +
    "       T.CARFATORY,\n" +
    "       T.CODESOURCE,\n" +
    "       T.MNATURE,\n" +
    "       T.MID,\n" +
    "       T.MCODE,\n" +
    "       T.MNAME,\n" +
    "       T.MSPEC,\n" +
    "       T.MUNIT,\n" +
    "       T.MBRAND,\n" +
    "       T.MBARCODE,\n" +
    "       T.SPELLCODE,\n" +
    "       T.ASSEMBLYCODE,\n" +
    "       T.ASSEMBLYNAME,\n" +
    "       T.LOAD,\n" +
    "       T.ERSATZ,\n" +
    "       T.AvgTotal,\n" +
    "       T.JobPrice,\n" +
    "       T.SalePrice,\n" +
    "       T.ServicePrice,\n" +
    "       T.ISUSE,\n" +
    "       T.PuCyc,\n" +
    "       T.Sfdzc,\n" +
    "       T.SCCCODE,\n" +
    "       T.SCCNAME,\n" +
    "       T.ZXBZ,\n" +
    "       T.ISZXQDPZ,\n" +
    "       T.ISJPZXQDPZ,\n" +
    "       T.DYJXX,\n" +
    "       T.DAMAGEPRICE,\n" +
    "       T.ABTYPE\n" +    
    "  FROM FX13BJRTT_BASIC_MATERIEL@Sqlwll T, BASIC_MATERIEL_V@SQLWLL S\n" +
    " WHERE T.MID = S.\"mID\"";

            //查一体化
            string sql = sqlAll + " And T.MCODE like '%" + mcode + "%'";
            dgPV.DataSource = db.Dao.searchDS("zj", sql).Tables[0];

            //查待下发物料
            //sql = sqlAll +
            //" and exists" +
            //"(select 1" +
            //"         from tm_part_material_info pm, t_sys_organization@dmsct so" +
            //"        where pm.net_code = so.org_id" +
            //"          and so.agents_code is not null" +
            //"          and pm.material_code = T.MCODE" +
            //"          and pm.last_updated_date < S.\"AlterDay\")";
            //dgPV_DMS.DataSource = db.Dao.searchDS("zj", sql).Tables[0];




        }
    }
}
